<template>
  <div>
    <r-search
      ref="search"
      :searchData="searchData"
      :searchForm="searchForm"
      :searchHandle="searchHandle"
      :inline="true"
    />
    <r-table
      :isPagination="true"
      :isHandle="true"
      :tableData="tableData"
      :tableCols="tableCols"
      :tablePage="pagination"
      :loading="tableLoading"
      :tableHandles="tableHandles"
      :isSelection="false"
      @refresh="page()"
    />
  </div>
</template>
<script>
export default {
  data() {
    return {
      searchData: {
        batteryNo: "", //Battery Number
        typeName: "", //TypeName
        beginTime: "", //Start Time
        endTime: "" //End Time
      },
      searchForm: [
        {
          type: "input",
          placeholder: "Battery Number",
          prop: "batteryNo",
          width: 240
        },
        {
          type: "input",
          placeholder: "Type Name",
          prop: "typeName",
          width: 230
        },
        {
          type: "date",
          placeholder: "Start Time",
          prop: "ctime",
          width: 230,
          change: val => {
            this.searchData.ctime = val;
          }
        },
        {
          type: "date",
          placeholder: "End Time",
          prop: "validityTime",
          width: 230,
          change: val => {
            this.searchData.validityTime = val;
          }
        }
      ],
      searchHandle: [
        {
          type: "primary",
          label: "Search",
          plain: true,
          handle: e => {
            this.zeroFn();
            this.getData();
          }
        },
        {
          label: "Reset",
          buttonss: true,
          icon: "el-icon-refresh-right",
          handle: e => {
            this.searchData = {
              batteryNo: "", //Battery Number
              typeName: "", //TypeName
              beginTime: "", //Start Time
              endTime: "" //End Time
            };
            this.zeroFn();
            this.getData();
          }
        }
      ],
      tableLoading: false,
      tableData: [],
      tableCols: [
        { label: "Battery Number", prop: "batteryNo" },
        { label: "Type Name", prop: "typeName" },
        { label: "Contents Warning", prop: "alarm" },
        { label: "Time Of Reporting", prop: "ctime" }
        // {
        //   label: "PackagePaymentStatus", prop: "status",
        //   itemClass: e => (e.status == 0 ? 'danger' : ''),
        //   formatter: e => (e.status == 0 ? '待Payment' : e.status == 1 ? '已Payment' : '--')
        // },
      ],
      tableHandles: [
        {
          label: "Battery Alarm Data Export",
          type: "primary",
          icon: "el-icon-download",
          // titles:
          //   "可以根据Battery Number、TypeName、Start Time、End Time筛选出订单再Export，也可以不选，直接ExportWhole订单",
          plain: true,
          loading: false,
          handle: async e => {
            const res = await this.apis.batteryAlarmExport(this.searchData);
            this.$message({
              type: res.code == 200 ? "success" : "error",
              message: res.code == 200 ? "success" : "error"
            });
            location.href = process.env.VUE_APP_URL + res.msg;
          }
        }
      ],
      pagination: { limit: 10, offset: 1, total: 0 },
      totalList: {}
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    zeroFn() {
      this.pagination.limit = 10;
      this.pagination.offset = 1;
      this.pagination.total = 0;
    },
    async getData() {
      let parm = {
        ...this.searchData,
        ...{
          pageNum: this.pagination.offset,
          pageSize: this.pagination.limit
        }
      };
      var res = await this.apis.batteryAlarmList(parm);
      this.tableData = res.rows || [];
      this.pagination.total = res.total;
    },
    page() {
      this.getData();
    }
  }
};
</script>

<style scoped lang="scss"></style>
